package org.veloxbot.api.utils;

import java.awt.Color;

/**
 * @author Velox
 */
public class ColorUtil {

	/**
	 * Gets the percentage between the two colors. [0-100]
	 *
	 * @param c1 The first color to compare.
	 * @param c2 The second color to compare.
	 * @return The percentage between the two colors. [0-100]
	 */
	public static int percent(final Color c1, final Color c2) {
		final int r = Math.abs(c1.getRed() - c2.getRed());
		final int g = Math.abs(c1.getGreen() - c2.getGreen());
		final int b = Math.abs(c1.getBlue() - c2.getBlue());
		return ((r / 255) + (g / 255) + (b / 255)) / 3 * 100;
	}

	/**
	 * Gets the tolerance between the two given colors.
	 *
	 * @param c1 The first color to compare.
	 * @param c2 The second color to compare.
	 * @return The tolerance between the two given colors.
	 */
	public static int dist(final Color c1, final Color c2) {
		final int r = Math.abs(c1.getRed() - c2.getRed());
		final int g = Math.abs(c1.getGreen() - c2.getGreen());
		final int b = Math.abs(c1.getBlue() - c2.getBlue());
		return (r + g + b) / 3;
	}
}
